package com.chengzhi.controller;

import com.chengzhi.service.TccService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: ruanchengzhi
 * @create: 2020-09-01 19:57
 **/
@RestController
@RequestMapping("/tcc")
public class TccController {

    @Resource
    private TccService tccService;

    @GetMapping("/commit")
    @GlobalTransactional(rollbackFor = Exception.class)
    public String commit() {
        Map<String, String> param = new HashMap<>();
        param.put("code", "1");
        return tccService.prepare(param);
    }

    @GetMapping("/rollback")
    @GlobalTransactional(rollbackFor = Exception.class)
    public String rollback() {
        Map<String, String> param = new HashMap<>();
        param.put("code", "2");
        return tccService.prepare(param);
    }

}
